package com.cfpl.admin_service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cfpl.admin_service.VO.PageQueryCondition;
import com.cfpl.admin_service.VO.VegEnvMonitoring;
import com.cfpl.admin_service.service.EnvironmentalMonitoringService;
import com.cfpl.project_common.pojo.EnvironmentalMonitoring;
import com.cfpl.project_common.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: wrp
 * @Date: 2023/10/25 - 20:33
 * @Description: com.cfpl.admin_service.controller
 * @version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/envMonitoring")
@Api(tags = "环境监测相关接口")
public class EnvMonitoringController {

    @Autowired
    private EnvironmentalMonitoringService envMonitoringService;

    /**
     * 功能描述：分页查询所有环境监测数据
     * @param currentPage 当前页
     * @param pageSize  页面条数
     * @param condition  查询条件
     * @return  环境监测数据
     */
    @ApiOperation("分页查询环境监测数据")
    @GetMapping("/queryAllEnvMonitoring")
    public BaseResult<PageQueryCondition> queryAll(int currentPage,int pageSize,String condition) {
        Page<EnvironmentalMonitoring> page = envMonitoringService.queryPage(currentPage,pageSize,condition);
        PageQueryCondition queryCondition = new PageQueryCondition(page,condition);
        return BaseResult.ok(queryCondition);
    }

    /**
     *  功能描述：新增环境检测数据
     * @param envMonitoring 环境监测数据
     * @return  环境监测数据
     */
    @ApiOperation("新增环境监测数据")
    @PostMapping("/addEnvMonitoring")
    public BaseResult<String> addEnvMonitoring(@RequestBody EnvironmentalMonitoring envMonitoring) {
        envMonitoringService.addEnvMonitoring(envMonitoring);
        return BaseResult.ok("success");
    }

    /**
     * 功能描述：根据id查询环境监测数据
     * @param Id 环境监测id
     * @return  环境监测数据
     */
    @ApiOperation("根据id查询环境监测数据")
    @GetMapping("/queryEnvMonitoringById/{id}")
    public BaseResult<EnvironmentalMonitoring> queryEnvMonitoringById(@PathVariable("id") Long Id) {
        EnvironmentalMonitoring envMonitoring = envMonitoringService.queryEnvMonitoringById(Id);
        return BaseResult.ok(envMonitoring);
    }

    /**
     * 功能描述：根据id修改环境监测数据
     * @param envMonitoring 环境监测数据
     * @return 修改后环境监测数据
     */
    @ApiOperation("修改环境监测数据")
    @PutMapping("/modifyEnvMonitoringById")
    public BaseResult modifyEnvMonitoringById(@RequestBody EnvironmentalMonitoring envMonitoring) {
        envMonitoringService.updateEnvMonitoring(envMonitoring);
        return BaseResult.ok(envMonitoring);
    }

    /**
     * 功能描述：根据id删除环境监测数据
     * @param id 环境监测数据 id
     * @return  删除成功信息
     */
    @ApiOperation("根据id删除环境监测数据")
    @DeleteMapping("/deleteEnvMonitoringById/{id}")
    public BaseResult deleteEnvMonitoringById(@PathVariable("id")Long id) {
        envMonitoringService.removeEnvMonitoringById(id);
        return BaseResult.ok("delete success");
    }

    /**
     * 功能描述：批量删除环境监测数据
     * @param Ids 环境监测数据id集合
     * @return 删除成功信息
     */
    @ApiOperation("批量删除环境监测数据")
    @DeleteMapping("/deleteEnvMonitoringList")
    public BaseResult<String> deleteEnvMonitoringList(@RequestParam("Ids")List<Long> Ids) {
        envMonitoringService.deleteBatchByIds(Ids);
        return BaseResult.ok("delete success");
    }


}
